<?php
/**
 * 新闻
 */
namespace app\model;

use think\Model;

class NewsModel extends Model
{
  protected $name = 'news';
  /**
    * 新闻列表
    *
    */
   public function GetList($where){
    $NewsModel=new NewsModel;
    $result=$NewsModel->field('id,title,img,desc,url,froms,updatetime,status')->where($where)->paginate();
    return $result;
   }
   /**
    * 新闻详情
    *
    */
   public function detail($id){
      $NewsModel = NewsModel::find($id);
      return $NewsModel;
   }
  /**
   * 添加
   *
  */
   public function AddData($param){
      $NewsModel = new NewsModel;
      $param['createtime']=time();
      $param['updatetime']=time();
      
      $field=['title','desc','img','url','froms','content','createtime','updatetime','role_id'];
      $NewsModel->allowField($field)->save($param);
      return $NewsModel->id; 
   }
  /**
   * 编辑
   *
  */
  public function EditData($param,$id){
   $NewsModel = NewsModel::find($id);
   $param['updatetime']=time();

   $field=['title','desc','img','url','froms','content','updatetime'];
  
   $NewsModel->allowField( $field)->save($param);
   return $id; 
  }
  /**
   * 修改禁用状态
   *
  */
  public function UpdateStatus($id){
   $NewsModel = NewsModel::find($id);
   $NewsModel->status=$NewsModel->status==1?0:1;
   $NewsModel->save();
   return true; 
  }
 /**
   * 删除
   *
  */
  public function Del($param){
   $update=[];
   foreach($param as $val){
       $update[]=['id'=>$val,'status'=>-1,'deletetime'=>time()];
   }
   if(!empty($update)){
      $NewsModel = new NewsModel;
      $NewsModel->saveAll($update);
   }
   return true; 
  }
}